<template>
  <div>
    <el-alert
    v-if="isLegal"
        title="输入出现不合法的情况:最大值小于最小值"
        type="error">
      </el-alert>
      <el-form :inline="true" v-show="isSearchCollapse" data-v-step="1" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
            <!-- 搜索框-->
         <el-form-item prop="name">
           <el-autocomplete
             class="input_height inline-input"
             v-model="searchForm.name"
             :fetch-suggestions="queryName"
             placeholder="姓名"
             @select="handleSelect"
           ></el-autocomplete>
                <!-- <el-input size="small" v-model="searchForm.name" placeholder="姓名" :disabled="role > 3" clearable></el-input> -->
         </el-form-item>
         <el-form-item prop="institute">
           <el-autocomplete
             class="inline-input"
             v-model="searchForm.institute"
             :fetch-suggestions="queryInstitute"
             placeholder="学院"
             @select="handleSelect"
             :disabled="role > 1"
           ></el-autocomplete>
                <!-- <el-input size="small" v-model="searchForm.institute" placeholder="学院" :disabled="role > 1" clearable></el-input> -->
         </el-form-item>
         <el-form-item prop="grade">
                <el-input size="small" v-model="searchForm.grade" placeholder="年级" :disabled="role > 3" clearable></el-input>
         </el-form-item>
         <el-form-item prop="classe">
                <el-input size="small" v-model="searchForm.classe" placeholder="班级" :disabled="role > 3" clearable></el-input>
         </el-form-item>
         <el-form-item prop="studentId">
                <el-input size="small" v-model="searchForm.studentId" placeholder="学号" :disabled="role > 3" clearable></el-input>
         </el-form-item>
         <el-form-item prop="currentInstructor">
           <el-autocomplete
             class="inline-input"
             v-model="searchForm.currentInstructor"
             :fetch-suggestions="queryTeacher"
             placeholder="辅导员老师"
             @select="handleSelect"
           ></el-autocomplete>
                <!-- <el-input size="small" v-model="searchForm.currentInstructor" placeholder="当前辅导员" :disabled="role > 2" clearable></el-input> -->
         </el-form-item>
         <el-form-item prop="currentMoraleduPoint">
                <el-input size="small" v-model="searchForm.currentMoraleduPoint" :disabled="minimum !== ''" placeholder="查看当前德育分" clearable></el-input>
         </el-form-item>
         <el-form-item prop="currentMoraleduPoint">
                <el-input size="small" v-model="minimum":disabled="ismm" placeholder="查询区间的最小分数" clearable></el-input>
         </el-form-item>
         <el-form-item prop="currentMoraleduPoint">
                <el-input size="small" v-model="maximum" :disabled="ismm" placeholder="查询区间的最大分数" clearable></el-input>
         </el-form-item>
         <el-form-item prop="state">
                <el-input size="small" v-model="searchForm.state" placeholder="学籍状态" clearable></el-input>
         </el-form-item>
<!--         <el-form-item>
          <el-date-picker size="small" v-model="year" type="year" value-format="yyyy" placeholder="选择年"></el-date-picker>
          </el-form-item> -->
          <el-select v-model="year" multiple placeholder="选择学年" >
            <el-option
              v-for="item in academicYear"
              :key="item.academicYear"
              :label="item.academicYear"
              :value="item.academicYear">
            </el-option>
          </el-select>
          <el-form-item>
            <el-button type="primary" @click="judgeLegal()" size="small">查询</el-button>
            <el-button @click="resetSearch()" size="small">重置</el-button>
          </el-form-item>
          <p style="color: #C0C0C0;">提示:查询区间分数不能与查询当前分数同时使用！</p>
      </el-form>
        <!-- 导入导出-->
        <el-dialog  title="导入Excel" :visible.sync="isImportCollapse">
          <el-form :inline="true" v-show="isImportCollapse"  class="query-form" ref="importForm">
             <el-form-item>
              <el-button type="default" @click="downloadTpl()" size="small">下载模板</el-button>
             </el-form-item>
             <el-form-item prop="loginName">
                <el-upload
                  class="upload-demo"
                  :action="`${this.$http.BASE_URL}/moredumain/studentMoreduMain/import`"
                  :on-success="uploadSuccess"
                   :show-file-list="true">
                  <el-button size="small" type="primary">点击上传</el-button>
                  <div slot="tip" class="el-upload__tip">只允许导入“xls”或“xlsx”格式文件！</div>
                </el-upload>
            </el-form-item>
          </el-form>
      </el-dialog>
      <el-row>
        <el-button v-if="hasPermission('moredumain:studentMoreduMain:add')" type="primary" size="small" icon="el-icon-plus" @click="add()">新建</el-button>
        <el-button v-if="hasPermission('moredumain:studentMoreduMain:edit')" type="warning" size="small" icon="el-icon-edit-outline" @click="edit()"
         :disabled="dataListSelections.length != 1" plain>修改</el-button>
        <el-button v-if="hasPermission('moredumain:studentMoreduMain:del')" type="danger"   size="small" icon="el-icon-delete" @click="del()"
                  :disabled="dataListSelections.length <= 0" plain>删除
        </el-button>
        <el-button v-if="hasPermission('moredumain:studentMoreduMain:agree')" type="primary" @click="handle(selectId, '/commit/studentSubmit/process')" size="small" :disabled="isCheck">同意</el-button>
        <el-button v-if="hasPermission('moredumain:studentMoreduMain:disagree')" type="danger" @click="handle(selectId, '/commit/studentSubmit/disagerrprocess')" :disabled="isCheck" size="small">不同意</el-button>
        <el-button v-if="hasPermission('moredumain:studentMoreduMain:view')" type="primary" size="small" icon="el-icon-search" data-v-step="2" @click="queryNot()" v-show="queryNo !== false">查询全部</el-button>
        <el-button v-if="hasPermission('moredumain:studentMoreduMain:view')" type="primary" size="small" icon="el-icon-search" data-v-step="2" @click="queryNot()" v-show="queryNo !== true">查询未审核</el-button>
        <!-- <el-button v-if="hasPermission('moredumain:studentMoreduMain:view')" type="primary" size="small" @click="rever()">分数降序排序</el-button> -->
        <el-button type="primary" @click="guide()" id="qinziyang" size="small">开始教学</el-button>
        &nbsp;
        <v-tour name="myTour" :steps="steps" :options="myOptions">
          <template slot-scope="tour">
              <transition name="fade">
                <v-step
                  v-if="tour.steps[tour.currentStep]"
                  :key="tour.currentStep"
                  :step="tour.steps[tour.currentStep]"
                  :previous-step="tour.previousStep"
                  :next-step="tour.nextStep"
                  :stop="tour.stop"
                  :skip="tour.skip"
                  :is-first="tour.isFirst"
                  :is-last="tour.isLast"
                  :labels="tour.labels"
                >
                  <template v-if="tour.currentStep === 0">
                    <div slot="actions">
                      <button @click="tour.previousStep" class="btn btn-primary">上一步</button>
                      <button @click="tour.nextStep" class="btn btn-primary" v-show="isSearchCollapse === true">下一步</button>
                    </div>
                  </template>
                </v-step>
              </transition>
            </template>
        </v-tour>
        <el-button-group class="pull-right">
          <el-button
            type="default"
            size="small"
            icon="el-icon-search"
            data-v-step="0"
            @click="isSearchCollapse = !isSearchCollapse, isImportCollapse=false">
          </el-button>
            <el-button v-if="hasPermission('moredumain:studentMoreduMain:import')" type="default" size="small" icon="el-icon-upload2" title="导入" @click="isImportCollapse = !isImportCollapse, isSearchCollapse=false"></el-button>
            <el-button v-if="hasPermission('moredumain:studentMoreduMain:export')" type="default" size="small" icon="el-icon-download" title="导出"  data-v-step="4" @click="dialogVisible = true"></el-button>
            <!-- title="提示" -->
            <el-dialog
              :visible.sync="dialogVisible"
              width="30%"
              :before-close="handleClose"
              style="margin-left: 0px;">
              <span>导出 <span style="color: red;">{{searchForm.institute}} {{ searchForm.grade }} {{searchForm.classe}}</span> 数据</span>
              <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="exportExcel()">确 定</el-button>
              </span>
            </el-dialog>
            <el-button
              type="default"
              size="small"
              icon="el-icon-refresh"
              @click="refresh()">
            </el-button>
        </el-button-group>
      </el-row>
    <el-table
      :data="dataList"
      border
      :cell-class-name="tableRowClassName"
      @selection-change="selectionChangeHandle"
      @sort-change="sortChangeHandle"
      v-loading="loading"
      :cell-style="cellStyle"
      size="medium"
      @expand-change="detail"
      class="table">
      <el-table-column type="expand">
      <template slot-scope="scope">
      <el-tabs>
            <el-tab-pane label="学生副表_德育加分">
                  <el-table
                  border
                  @selection-change="selectionChangeHandle"
                  size="medium"
                  :data="scope.row.studentMoreduViceAddList"
                  style="width: 100%">
                  <el-table-column
                    type="selection"
                    header-align="center"
                    align="center"
                    width="50">
                  </el-table-column>
                <el-table-column
                    prop="addReason"
                    label="加分原因">
                  </el-table-column>
                <el-table-column
                    prop="addTime"
                    label="加分时间">
                  </el-table-column>
                <el-table-column
                    prop="addPoint"
                    label="加分数">
                  </el-table-column>
                <el-table-column
                    prop="addState"
                    label="审核状态">
                    <template slot-scope="scope">
                       {{ $dictUtils.getDictLabel("audit_status", scope.row.addState, '-') }}
                    </template>
                  </el-table-column>
                  <el-table-column
                      prop="auditTime"
                      label="审批时间">
                    </el-table-column>
                  <el-table-column
                    prop="addEnclosure"
                    label="附件">
                    <template slot-scope="scope" v-if="scope.row.addEnclosure">
                      <el-image
                        style="height: 50px;width:50px;margin-right:10px;"
                        :src="src"
                        v-for="(src, index) in scope.row.addEnclosure.split(',')" :key="index"
                        :preview-src-list="scope.row.addEnclosure.split(',')">
                      </el-image>
                    </template>
                  </el-table-column>
                  <el-table-column
                    header-align="center"
                    align="center"
                    :key="Math.random()"
                    width="200"
                    label="操作">
                    <template  slot-scope="scope">
                      <el-button v-if="hasPermission('moredumain:studentMoreduMain:agree')" type="text" icon="el-icon-circle-check" size="small" @click="handle(scope.row.id, '/commit/studentSubmit/process')" :disabled="scope.row.addState !== '0'">同意</el-button>
                      <el-button v-if="hasPermission('moredumain:studentMoreduMain:disagree')" type="text" icon="el-icon-circle-close" size="small" @click="handle(scope.row.id, '/commit/studentSubmit/disagerrprocess')" :disabled="scope.row.addState !== '0'">不同意</el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </el-tab-pane>
            <el-tab-pane label="学生副表-德育减分">
                  <el-table
                  border
                  size="medium"
                  :data="scope.row.studentMoreduViceSubList"
                  style="width: 100%">
                <el-table-column
                    prop="subReason"
                    label="扣分原因">
                  </el-table-column>
                <el-table-column
                    prop="subTime"
                    label="扣分时间">
                  </el-table-column>
                <el-table-column
                    prop="subPoint"
                    label="扣分数">
                  </el-table-column>
                </el-table>
              </el-tab-pane>
            </el-tabs>
      </template>
      </el-table-column>
    <el-table-column
        prop="name"
        show-overflow-tooltip
        sortable="custom"
        label="姓名">
      </el-table-column>
    <el-table-column
        prop="institute"
        show-overflow-tooltip
        sortable="custom"
        label="学院">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false" v-if="hasPermission('moredumain:studentMoreduMain:view')" @click="clickQuery(scope.row.institute)">{{scope.row.institute}}</el-link>
          <span v-else>{{scope.row.institute}}</span>
        </template>
      </el-table-column>
    <el-table-column
        prop="grade"
        show-overflow-tooltip
        sortable="custom"
        label="年级">
      </el-table-column>
    <el-table-column
        prop="classe"
        show-overflow-tooltip
        sortable="custom"
        label="班级">
      </el-table-column>
    <el-table-column
        prop="studentId"
        show-overflow-tooltip
        sortable="custom"
        label="学号">
      </el-table-column>
    <el-table-column
        prop="currentInstructor"
        show-overflow-tooltip
        sortable="custom"
        label="当前辅导员">
        <template slot-scope="scope">
          <el-link  type="primary" :underline="false" v-if="hasPermission('moredumain:studentMoreduMain:view')" @click="clickTeacher(scope.row.currentInstructor)">{{scope.row.currentInstructor}}</el-link>
          <span v-else>{{scope.row.currentInstructor}}</span>
        </template>
      </el-table-column>
    <el-table-column
        prop="currentMoraleduPoint"
        show-overflow-tooltip
        sortable="custom"
        label="德育分">
      </el-table-column>
      <el-table-column
          prop="state"
          show-overflow-tooltip
          sortable="custom"
          label="学籍状态">
        </el-table-column>
      <el-table-column
        header-align="center"
        align="center"
        :key="Math.random()"
        width="200"
        label="操作">
        <template  slot-scope="scope">
          <el-button v-if="hasPermission('moredumain:studentMoreduMain:view')" type="text" icon="el-icon-view" size="small" @click="view(scope.row.id)">查看</el-button>
          <el-button v-if="hasPermission('moredumain:studentMoreduMain:edit')" type="text" icon="el-icon-edit" size="small" @click="edit(scope.row.id)">修改</el-button>
          <el-button v-if="hasPermission('moredumain:studentMoreduMain:del')" type="text"  icon="el-icon-delete" size="small" @click="del(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageNo"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="total"
      background
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
        <!-- 弹窗, 新增 / 修改 -->
    <StudentMoreduMainForm  ref="studentMoreduMainForm" @refreshDataList="refreshList"></StudentMoreduMainForm>
  </div>
</template>

<script>
  import StudentMoreduMainForm from './StudentMoreduMainForm'
  import pinyin from 'pinyin-match'
  export default {
    data () {
      return {
        searchForm: {
          name: '',
          institute: '',
          grade: '',
          classe: '',
          studentId: '',
          currentInstructor: '',
          currentMoraleduPoint: '',
          state: '',
          queryAcademicYear: ''
        },
        academicYear: [], // 当前存在的学年
        steps: [
          {
            target: '[data-v-step="0"]',  // We're using document.querySelector() under the hood
            content: `请先点击该按钮再点击下一步`,
            params: {
              placement: 'top'
            }
          },
          {
            target: '[data-v-step="1"]',
            content: '可以在这里查询您想查询的信息',
            params: {
              placement: 'top'
            }
          },
          {
            target: '[data-v-step="2"]',
            content: '点击这里可以查询到当前没有审核的学生',
            params: {
              placement: 'top'
            }
          },
          {
            target: '.qzy',
            // el-table_1_column_8     is-leaf is-sortable el-table__cell
            content: '点击这里可以实现升序降序排列',
            params: {
              placement: 'top'
            }
          },
          {
            target: '[data-v-step="4"]',
            content: '可以导出按当前查询的内容',
            params: {
              placement: 'top'
            }
          },
          {
            target: '.qinziyang',
            content: '点击可查看详细信息',
            params: {
              placement: 'top'
            }
          }
        ],
        myOptions: {
          useKeyboardNavigation: false,
          labels: {
            buttonSkip: '跳过教学',
            buttonPrevious: '上一步',
            buttonNext: '下一步',
            buttonStop: '结束教程'
          },
          highlight: true
        },
        dialogVisible: false,
        minimum: '',
        maximum: '',
        year: [],
        isLegal: false,
        sortDes: false,
        isSearchCollapse: false,
        dataList: [],
        pageNo: 1,
        pageSize: 10,
        total: 0,
        nameList: [], // 把所有的名字存到前端
        instituteList: [], // 把所有的机构存到前端
        teacherList: [], // 把所有教师的名字存到前端
        orderBy: '',
        queryNo: false, // 查询未审核状态
        dataListSelections: [],
        isImportCollapse: false,
        loading: false,
        src: '', // 附件
        selectId: '', // 多选id
        selectIdList: [],
        isCheck: true,
        reviewer: '', // 辅导员老师姓名
        officeName: '', // 老师所属机构
        studentName: '',
        instructor: '',
        role: 0, // 定义 0为总管理员、1为学工处、2为学院老师、3为辅导员老师、4为学生
        tempID: '', // 临时id
        tempList: [], // 临时list
        notAudit: [], // 没有审核的id
        ismm: false // 是否可以选择最大值最小值
      }
    },
    watch: {
      'searchForm.currentMoraleduPoint' (newname, oldname) {
        if (newname === '') {
          this.ismm = false
          this.maximum = ''
          this.minimum = ''
        } else {
          this.ismm = true
          this.maximum = ''
          this.minimum = ''
        }
      }
    },
    components: {
      StudentMoreduMainForm
    },
    mounted () {
      this.year.push('2022-2023')
      // 获取所有的学生、老师姓名，机构
      this.$http({
        url: '/moredumain/studentMoreduMain/queryPinyin',
        method: 'get'
      }).then(({data}) => {
        if (data && data.success) {
          this.academicYear = data.academicYear
          this.nameList = data.nameList
          this.instituteList = data.instituteList
          this.teacherList = data.teacherList
        }
      })
      this.$nextTick(() => {
        document.getElementsByClassName('el-table_1_column_8')[0].classList.add('qzy')
      })
    },
    activated () {
      this.getUserInfo()
    },
    methods: {
      tableRowClassName ({ row, rowIndex }) {
        if (rowIndex === 0) {
          return 'qinziyang'
        }
      },
      guide () {
        this.$tours['myTour'].start()
      },
      clickQuery (institute) {
        this.resetSearch()
        this.searchForm.institute = institute
        this.getUserInfo()
      },
      clickTeacher (currentInstructor) {
        this.resetSearch()
        this.searchForm.currentInstructor = currentInstructor
        this.getUserInfo()
      },
      queryName (queryString, cb) {
        var restaurants = this.nameList
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
        // 调用 callback 返回建议列表的数据
        cb(results)
      },
      queryInstitute (queryString, cb) {
        var restaurants = this.instituteList
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
        // 调用 callback 返回建议列表的数据
        cb(results)
      },
      queryTeacher (queryString, cb) {
        var restaurants = this.teacherList
        var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
        // 调用 callback 返回建议列表的数据
        cb(results)
      },
      createFilter (queryString) {
        return (restaurant) => {
          return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0 || pinyin.match(restaurant.value, queryString))
        }
      },
      handleSelect (item) {
      },
      // 当刷新是调用重置再继续调用
      refresh () {
        this.notAudit = []
        this.getUserInfo()
      },
      rever () {
        this.sortDes = !this.sortDes
        this.refreshList()
      },
      // 按照降序排列
      sort () {
        this.loading = true
        this.$http({
          url: '/moredumain/studentMoreduMain/sort',
          method: 'get',
          params: {
            'pageNo': this.pageNo,
            'pageSize': this.pageSize,
            'orderBy': this.orderBy,
            'maximum': this.maximum,
            'minimum': this.minimum,
            ...this.searchForm
          }
        }).then(({data}) => {
          if (data && data.success) {
            this.dataList = data.page.list
            this.total = data.page.count
            this.loading = false
          }
        })
      },
      // 获取当前登录用户信息
      getUserInfo () {
        this.$http({
          url: '/sys/user/info',
          method: 'get'
        }).then(({data}) => {
          if (data.success) {
            // 学院账号
            if (data.user.roleIds === '52211ea85fbe423a8f3d11c39e09dc51') {
              this.role = 2
              this.officeName = data.user.office.name
              this.searchForm.institute = this.officeName
            }
            if (data.user.roleIds === '2a21eb97b6dc4b1ba64ca654d38be348') {
              // 辅导员老师账号
              this.role = 3
              this.officeName = data.user.office.name
              this.reviewer = data.user.name
              this.searchForm.institute = this.officeName
              this.searchForm.currentInstructor = this.reviewer
            }
            if (data.user.roleIds === 'b930ac75924c47f99ac92c6fc8c3accb') {
              // 学生账号
              this.role = 4
              this.searchForm.studentId = data.user.no
            }
            this.refreshList()
          }
        })
      },
      // 一键处理
      handle (id, url) {
        this.loading = true
        this.$http({
          url: url,
          method: 'get',
          params: {
            'ids': id,
            'approverPeople': this.reviewer
          }
        }).then(({data}) => {
          if (data && data.success) {
            this.isCheck = true
            this.loading = false
            this.refresh()
          }
        })
      },
      judgeLegal () {
        if (this.maximum < this.minimum) {
          this.isLegal = true
        } else {
          this.isLegal = false
          this.refreshList()
        }
      },
      // 获取数据列表
      refreshList () {
        if (this.sortDes === true) {
          this.sort()
        } else if (this.queryNo === true) {
          this.notQuery()
        } else {
          if (this.year.length === 0) {
            this.$message.error('请输入查询学年')
            return
          }
          this.searchForm.queryAcademicYear = ''
          for (let i = 0; i < this.year.length; i++) {
            if (i !== 0) {
              this.searchForm.queryAcademicYear += ','
            }
            this.searchForm.queryAcademicYear += this.year[i]
          }
          this.loading = true
          this.$http({
            url: '/moredumain/studentMoreduMain/list',
            method: 'get',
            params: {
              'pageNo': this.pageNo,
              'pageSize': this.pageSize,
              'orderBy': this.orderBy,
              'maximum': this.maximum,
              'minimum': this.minimum,
              ...this.searchForm
            }
          }).then(({data}) => {
            if (data && data.success) {
              this.dataList = data.page.list
              this.total = data.page.count
              this.loading = false
            }
          })
        }
      },
      // 循环列表次
      // queryNot () {
      //   this.notAudit = []
      //   for (var i = 0; i < this.dataList.length; i++) {
      //     this.tempID = this.dataList[i].id
      //     this.detailId(this.tempID)
      //   }
      //   // 因为代码执行需要时间，因此需要等待两秒后才执行
      //   setTimeout(() => {
      //   // 需要延迟的代码 :3秒后延迟跳转到首页，可以加提示什么的
      //     if (this.notAudit.length === 0) {
      //       this.$message({
      //         title: '成功',
      //         message: '当前页都已审核',
      //         type: 'seccess',
      //         duration: 2000
      //       })
      //     }
      //     // 延迟时间：2秒
      //   }, 2000)
      // },
      // 查询未审核，从后端返回
      queryNot () {
        this.queryNo = !this.queryNo
        this.refreshList()
      },
      notQuery () {
        this.loading = true
        this.$http({
          url: '/moredumain/studentMoreduMain/queryNot',
          method: 'get',
          params: {
            'pageNo': this.pageNo,
            'pageSize': this.pageSize,
            'orderBy': this.orderBy,
            'maximum': this.maximum,
            'minimum': this.minimum,
            ...this.searchForm
          }
        }).then(({data}) => {
          if (data && data.success) {
            this.dataList = data.page.list
            this.total = data.page.count
            this.loading = false
          }
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageNo = 1
        this.refreshList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageNo = val
        this.refreshList()
      },
      // 多选
      selectionChangeHandle (val) {
        var a = 0
        this.selectIdList = []
        this.dataListSelections = val
        this.dataListSelections.map(item => {
          this.selectIdList.push(item.id)
          if (item.addState === '0') {
            a++
          }
        })
        if (a === this.dataListSelections.length && this.dataListSelections.length !== 0) {
          this.isCheck = false
        } else {
          this.isCheck = true
        }
        this.selectId = this.selectIdList.toString()
      },

    // 排序
      sortChangeHandle (obj) {
        if (obj.order === 'ascending') {
          this.orderBy = obj.prop + ' asc'
        } else if (obj.order === 'descending') {
          this.orderBy = obj.prop + ' desc'
        } else {
          this.orderBy = ''
        }
        this.refreshList()
      },
      // 新增
      add () {
        this.$refs.studentMoreduMainForm.init('add', '')
      },
      // 修改
      edit (id) {
        id = id || this.dataListSelections.map(item => {
          return item.id
        })[0]
        this.$refs.studentMoreduMainForm.init('edit', id)
      },
      // 查看
      view (id) {
        this.$refs.studentMoreduMainForm.init('view', id)
      },
      // 删除
      del (id) {
        let ids = id || this.dataListSelections.map(item => {
          return item.id
        }).join(',')
        this.$confirm(`确定删除所选项吗?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true
          this.$http({
            url: '/moredumain/studentMoreduMain/delete',
            method: 'delete',
            params: {'ids': ids}
          }).then(({data}) => {
            if (data && data.success) {
              this.$message.success(data.msg)
              this.refreshList()
            }
            this.loading = false
          })
        })
      },
     // 查看详情
      detail (row) {
        this.$http.get(`/moredumain/studentMoreduMain/queryById?id=${row.id}`).then(({data}) => {
          this.dataList.forEach((item, index) => {
            if (item.id === row.id) {
              item.studentMoreduViceAddList = data.studentMoreduMain.studentMoreduViceAddList
              item.studentMoreduViceSubList = data.studentMoreduMain.studentMoreduViceSubList
            }
          })
        })
      },
      // 查看详情
      detailId (id) {
        this.$http.get(`/moredumain/studentMoreduMain/queryById?id=` + id).then(({data}) => {
          this.tempList = data.studentMoreduMain.studentMoreduViceAddList
          this.tempID = data.studentMoreduMain.id
          if (this.tempList.length > 0) {
            for (let k = 0; k < this.tempList.length; k++) {
              if (this.tempList[k].addState === '0') {
                this.notAudit.push(this.tempID)
                return
              }
            }
          }
          this.tempList = data.studentMoreduMain.studentMoreduViceSubList
          if (this.tempList.length > 0) {
            for (let w = 0; w < this.tempList.length; w++) {
              if (this.tempList[w].subState === '0') {
                this.notAudit.push(this.tempID)
                return
              }
            }
          }
        })
      },
      cellStyle ({row, column, rowIndex, columnIndex}) {
        if (this.notAudit.indexOf(row.id) > -1) {
          return 'border:2px;border: 1px solid #caffc2;'
        }
        return ''
      },
      // 导入成功
      uploadSuccess (res, file) {
        if (res.success) {
          this.$message.success({dangerouslyUseHTMLString: true,
            message: res.msg})
        } else {
          this.$message.error(res.msg)
        }
      },
      // 下载模板
      downloadTpl () {
        this.$utils.download('/moredumain/studentMoreduMain/import/template')
      },
      handleClose (done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done()
          })
          .catch(_ => {})
      },

      exportExcel () {
        let params = {
          ...this.searchForm
        }
        if (this.searchForm.studentId !== '' && this.searchForm.studentId !== undefined) {
          this.$utils.download('/moredumain/studentMoreduMain/exportByIndividual', params)
        } else {
          this.$utils.download('/moredumain/studentMoreduMain/export', params)
        }
        this.dialogVisible = false
      },
      resetSearch () {
        this.$refs.searchForm.resetFields()
        this.refreshList()
      },
      queryAbove () {
        this.loading = true
        this.$http({
          url: '/moredumain/studentMoreduMain/queryAbove',
          method: 'get',
          params: {
            'pageNo': this.pageNo,
            'pageSize': this.pageSize,
            'orderBy': this.orderBy,
            ...this.searchForm
          }
        }).then(({data}) => {
          if (data && data.success) {
            this.dataList = data.page.list
            this.total = data.page.count
            this.loading = false
          }
        })
        // 因为代码执行需要时间，因此需要等待两秒后才执行
        setTimeout(() => {
        // 需要延迟的代码 :3秒后延迟跳转到首页，可以加提示什么的
          if (this.notAudit.length === 0) {
            this.$message({
              title: '成功',
              message: '查询成功，共有' + this.total + '数据',
              type: 'seccess',
              duration: 2000
            })
          }
          // 延迟时间：2秒
        }, 2000)
      }
    }
  }
</script>
<style lang="less" scoped>
  /deep/ .el-input__inner  {
    height: 32px;
  }
</style>
